#include"head.h"

int cmd_split(char*buf,train_t* command_data)
{
   char* command_str;
   command_str = strtok(buf, " ");

   printf("buf:%s,op_type:%s\n",buf,command_str);

    if (strcmp(command_str, "ls") == 0)
        command_data->op = ls;
    else if (strcmp(command_str, "cd") == 0)
        command_data->op = cd;
    else if (strcmp(command_str, "pwd") == 0)
        command_data->op = pwd;
    else if (strcmp(command_str, "download") == 0)
        command_data->op = download;
    else if (strcmp(command_str, "upload") == 0)
        command_data->op = upload;
    else if (strcmp(command_str, "rm") == 0)
        command_data->op = rm;
    else if (strcmp(command_str, "cdir") == 0)
        command_data->op = cdir;
    else
    {
        return -1;
    }
    char* command_arg = strtok(NULL, " ");
    if(command_arg==NULL)
    {
        printf("fail to read\n");
    }
    printf("2\n");
    strncpy(command_data->path,command_arg,strlen(command_arg));
    printf("op:%d\n",command_data->op);
    printf("%s\n",command_arg);

    return 0;
}

int main()
{
    char buf[200]={0};
    train_t command_data;
    memset(&command_data,0,sizeof(train_t));
    printf("please input the command\n");
    fgets(buf,sizeof(buf),stdin);
    printf("%s\n",buf);


    cmd_split(buf,&command_data);

    return 0;
}
